package com.jm.bishe.controller;

import com.google.code.kaptcha.Constants;
import com.jm.bishe.entity.Result;
import com.jm.bishe.entity.LoginBody;
import com.jm.bishe.entity.UserRegister;
import com.jm.bishe.service.Impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/sys/usr")
public class UserController {


    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/register")
    @ResponseBody
    public Result userRegister(@RequestBody UserRegister userRegisiter){
        return userService.register(userRegisiter);
    }


    @PostMapping("/login")
    @ResponseBody
    public Result userLogin(@RequestBody LoginBody loginBody, HttpServletRequest request){
        String checkCode = (String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        return userService.login(loginBody,checkCode);
//        return null;
    }
}
